using System.Collections.Generic;
using CodePlex.DnD4eCampaignManager.DnD4e;
using NUnit.Framework;

namespace CodePlex.DnD4eCampaignManager.CampaignManagerTests.DnD4eTests
{
    [TestFixture]
    public class ListExtensionMethodTests
    {
        [Test]
        public void EquivelantReturnsFalseForListsWithDifferentElements()
        {
            LocalTestObject item1 = new LocalTestObject { Name = "1" };
            LocalTestObject item2 = new LocalTestObject { Name = "2" };
            LocalTestObject item3 = new LocalTestObject { Name = "3" };
            LocalTestObject item4 = new LocalTestObject { Name = "4" };
            List<LocalTestObject> list1 = new List<LocalTestObject> { item1, item2, item3 };
            List<LocalTestObject> list2 = new List<LocalTestObject> { item1, item3, item4 };
            Assert.IsFalse(list1.Equivalent(list2));
        }

        [Test]
        public void EquivelantReturnsFalseForListsWithDifferentNumberOfElements()
        {
            LocalTestObject item1 = new LocalTestObject { Name = "1" };
            LocalTestObject item2 = new LocalTestObject { Name = "2" };
            LocalTestObject item3 = new LocalTestObject { Name = "3" };
            List<LocalTestObject> list1 = new List<LocalTestObject> { item1, item2, item3 };
            List<LocalTestObject> list2 = new List<LocalTestObject> { item1, item3 };
            Assert.IsFalse(list1.Equivalent(list2));
        }

        [Test]
        public void EquivelantReturnsTrueForListsWithSameElementsInDifferentOrder()
        {
            LocalTestObject item1 = new LocalTestObject { Name = "1" };
            LocalTestObject item2 = new LocalTestObject { Name = "2" };
            LocalTestObject item3 = new LocalTestObject { Name = "3" };
            List<LocalTestObject> list1 = new List<LocalTestObject> { item1, item2, item3 };
            List<LocalTestObject> list2 = new List<LocalTestObject> { item1, item3, item2 };
            Assert.IsTrue(list1.Equivalent(list2));
        }

        [Test]
        public void EquivelantReturnsTrueForListsWithSameElementsInSameOrder()
        {
            LocalTestObject item1 = new LocalTestObject { Name = "1" };
            LocalTestObject item2 = new LocalTestObject { Name = "2" };
            LocalTestObject item3 = new LocalTestObject { Name = "3" };
            List<LocalTestObject> list1 = new List<LocalTestObject> { item1, item2, item3 };
            List<LocalTestObject> list2 = new List<LocalTestObject> { item1, item2, item3 };
            Assert.IsTrue(list1.Equivalent(list2));
        }

        [Test]
        public void ToCommaDelimitedStringConvertsListOfStringsToString()
        {
            List<string> list = new List<string> { "Item1", "Item2", "Item3" };
            const string concatenatedList = "Item1, Item2, Item3";
            Assert.AreEqual(concatenatedList, list.ToCommaDelimitedString());
        }

        [Test]
        public void ToListOfStringsConvertsStringToListOfStrings()
        {
            List<string> list = new List<string> { "Item1", "Item2", "Item3" };
            const string concatenatedList = "item1, item2, item3";
            Assert.AreEqual(list, concatenatedList.ToListOfStrings());
        }

        private class LocalTestObject
        {
            public string Name { get; set; }
        }
    }
}